/*********************************************************************
	Rhapsody	: 7.6
	Login		: Pawel
	Component	: DefaultComponent
	Configuration 	: DefaultConfig
	Model Element	: ScheduleApplication
//!	Generated Date	: Sun, 27, Nov 2011 
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/ScheduleApplication.java
*********************************************************************/

package CargoLiftSystem;

//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.animation.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;
//## auto_generated
import com.ibm.rational.rhapsody.animcom.animMessages.*;

//----------------------------------------------------------------------------
// CargoLiftSystem/ScheduleApplication.java                                                                  
//----------------------------------------------------------------------------

//## package CargoLiftSystem 


//## class ScheduleApplication 
public class ScheduleApplication implements RiJStateConcept, Animated {
    
    //#[ ignore
    // Instrumentation attributes (Animation)
    private Animate animate;
    
    public static AnimClass animClassScheduleApplication = new AnimClass("CargoLiftSystem.ScheduleApplication",false);
    //#]
    
    public Reactive reactive;		//## ignore 
    
    protected boolean isTaskQueueEmpty = true;		//## attribute isTaskQueueEmpty 
    
    protected java.util.Queue<Integer> liftCalls;		//## attribute liftCalls 
    
    protected boolean[] requestedFloors;		//## attribute requestedFloors 
    
    protected java.util.Queue<Integer> selectedFloors;		//## attribute selectedFloors 
    
    protected Lift itsLift;		//## link itsLift 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    //## auto_generated 
    public  ScheduleApplication(RiJThread p_thread) {
        try {
            animInstance().notifyConstructorEntered(animClassScheduleApplication.getUserClass(),
               new ArgData[] {
               });
        
        reactive = new Reactive(p_thread);
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    /**
     * @param floor
    */
    //## operation addLiftCalls(int) 
    public void addLiftCalls(int floor) {
        try {
            animInstance().notifyMethodEntered("addLiftCalls",
               new ArgData[] {
                   new ArgData(int.class, "floor", AnimInstance.animToString(floor))
               });
        
        //#[ operation addLiftCalls(int) 
             liftCalls.offer(floor); 
             System.out.print("adding new lift calls, we have: ");
             for(int a : liftCalls)
             {
               System.out.print(" " + a );
             
             }                        
             System.out.println("");
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    /**
     * @param floor
    */
    //## operation addSelectedFloors(int) 
    public void addSelectedFloors(int floor) {
        try {
            animInstance().notifyMethodEntered("addSelectedFloors",
               new ArgData[] {
                   new ArgData(int.class, "floor", AnimInstance.animToString(floor))
               });
        
        //#[ operation addSelectedFloors(int) 
               selectedFloors.add(floor);
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    /**
     * @param floor
    */
    //## operation getLiftCallContains(int) 
    public boolean getLiftCallContains(int floor) {
        try {
            animInstance().notifyMethodEntered("getLiftCallContains",
               new ArgData[] {
                   new ArgData(int.class, "floor", AnimInstance.animToString(floor))
               });
        
        //#[ operation getLiftCallContains(int) 
        return liftCalls.contains(floor);
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation getLiftCalls() 
    public java.util.Queue<Integer> getLiftCalls() {
        try {
            animInstance().notifyMethodEntered("getLiftCalls",
               new ArgData[] {
               });
        
        //#[ operation getLiftCalls() 
        return liftCalls;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation getLiftCallsPoll() 
    public int getLiftCallsPoll() {
        try {
            animInstance().notifyMethodEntered("getLiftCallsPoll",
               new ArgData[] {
               });
        
        //#[ operation getLiftCallsPoll() 
        return liftCalls.poll();
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation getRequestedFloorPoll() 
    public int getRequestedFloorPoll() {
        try {
            animInstance().notifyMethodEntered("getRequestedFloorPoll",
               new ArgData[] {
               });
        
        //#[ operation getRequestedFloorPoll() 
        return selectedFloors.poll();
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation getRequestedFloors() 
    public boolean[] getRequestedFloors() {
        try {
            animInstance().notifyMethodEntered("getRequestedFloors",
               new ArgData[] {
               });
        
        //#[ operation getRequestedFloors() 
        return requestedFloors;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation getSelectedFloors() 
    public java.util.Queue<Integer> getSelectedFloors() {
        try {
            animInstance().notifyMethodEntered("getSelectedFloors",
               new ArgData[] {
               });
        
        //#[ operation getSelectedFloors() 
        return selectedFloors;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    /**
     * @param floor
    */
    //## operation getSelectedFloorsContains(int) 
    public boolean getSelectedFloorsContains(int floor) {
        try {
            animInstance().notifyMethodEntered("getSelectedFloorsContains",
               new ArgData[] {
                   new ArgData(int.class, "floor", AnimInstance.animToString(floor))
               });
        
        //#[ operation getSelectedFloorsContains(int) 
         return selectedFloors.contains(floor); 
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    /**
     * @param floor
    */
    //## operation hasCallForFloor(int) 
    public boolean hasCallForFloor(int floor) {
        try {
            animInstance().notifyMethodEntered("hasCallForFloor",
               new ArgData[] {
                   new ArgData(int.class, "floor", AnimInstance.animToString(floor))
               });
        
        //#[ operation hasCallForFloor(int) 
        if(requestedFloors[floor]==true)
        	return true;
        else 
        	return false;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation ifLiftCallsEmpty() 
    public boolean ifLiftCallsEmpty() {
        try {
            animInstance().notifyMethodEntered("ifLiftCallsEmpty",
               new ArgData[] {
               });
        
        //#[ operation ifLiftCallsEmpty() 
        return liftCalls.isEmpty();
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation ifSelectedFloorsEmpty() 
    public boolean ifSelectedFloorsEmpty() {
        try {
            animInstance().notifyMethodEntered("ifSelectedFloorsEmpty",
               new ArgData[] {
               });
        
        //#[ operation ifSelectedFloorsEmpty() 
                  return selectedFloors.isEmpty();
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation ifTaskQueueEmpty() 
    public boolean ifTaskQueueEmpty() {
        try {
            animInstance().notifyMethodEntered("ifTaskQueueEmpty",
               new ArgData[] {
               });
        
        //#[ operation ifTaskQueueEmpty() 
        return isTaskQueueEmpty;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation newLiftCalls() 
    public java.util.Queue<Integer> newLiftCalls() {
        try {
            animInstance().notifyMethodEntered("newLiftCalls",
               new ArgData[] {
               });
        
        //#[ operation newLiftCalls() 
        liftCalls = new java.util.LinkedList<Integer>(); 
        
        return liftCalls;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation newSelectedFloors() 
    public java.util.Queue<Integer> newSelectedFloors() {
        try {
            animInstance().notifyMethodEntered("newSelectedFloors",
               new ArgData[] {
               });
        
        //#[ operation newSelectedFloors() 
           selectedFloors = new java.util.LinkedList<Integer>(); 
           return selectedFloors;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    /**
     * @param floor
    */
    //## operation removeFloor(int) 
    public void removeFloor(int floor) {
        try {
            animInstance().notifyMethodEntered("removeFloor",
               new ArgData[] {
                   new ArgData(int.class, "floor", AnimInstance.animToString(floor))
               });
        
        //#[ operation removeFloor(int) 
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation resetRequests() 
    public void resetRequests() {
        try {
            animInstance().notifyMethodEntered("resetRequests",
               new ArgData[] {
               });
        
        //#[ operation resetRequests() 
        for(int i=0; i<requestedFloors.length; i++)
        {
         	requestedFloors[i] = false;
        }
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    /**
     * @param emptyness
    */
    //## operation setTaskQueue(boolean) 
    public void setTaskQueue(boolean emptyness) {
        try {
            animInstance().notifyMethodEntered("setTaskQueue",
               new ArgData[] {
                   new ArgData(boolean.class, "emptyness", AnimInstance.animToString(emptyness))
               });
        
        //#[ operation setTaskQueue(boolean) 
                  isTaskQueueEmpty = emptyness;
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## auto_generated 
    public boolean getIsTaskQueueEmpty() {
        return isTaskQueueEmpty;
    }
    
    //## auto_generated 
    public void setIsTaskQueueEmpty(boolean p_isTaskQueueEmpty) {
        isTaskQueueEmpty = p_isTaskQueueEmpty;
    }
    
    //## auto_generated 
    public void setLiftCalls(java.util.Queue<Integer> p_liftCalls) {
        liftCalls = p_liftCalls;
    }
    
    //## auto_generated 
    private void setRequestedFloors(int i1, boolean p_requestedFloors) {
        requestedFloors[i1] = p_requestedFloors;
    }
    
    //## auto_generated 
    private void setSelectedFloors(java.util.Queue<Integer> p_selectedFloors) {
        selectedFloors = p_selectedFloors;
    }
    
    //## auto_generated 
    public Lift getItsLift() {
        return itsLift;
    }
    
    //## auto_generated 
    public void __setItsLift(Lift p_Lift) {
        itsLift = p_Lift;
        if(p_Lift != null)
            {
                animInstance().notifyRelationAdded("itsLift", p_Lift);
            }
        else
            {
                animInstance().notifyRelationCleared("itsLift");
            }
    }
    
    //## auto_generated 
    public void _setItsLift(Lift p_Lift) {
        if(itsLift != null)
            {
                itsLift.__setItsScheduleApplication(null);
            }
        __setItsLift(p_Lift);
    }
    
    //## auto_generated 
    public void setItsLift(Lift p_Lift) {
        if(p_Lift != null)
            {
                p_Lift._setItsScheduleApplication(this);
            }
        _setItsLift(p_Lift);
    }
    
    //## auto_generated 
    public void _clearItsLift() {
        animInstance().notifyRelationCleared("itsLift");
        itsLift = null;
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive implements AnimatedReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_add(AnimStates animStates) {
            animStates.add("ROOT");
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void rootState_enter() {
            animInstance().notifyStateEntered("ROOT");
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        /**  methods added just for design level debugging instrumentation */
        public boolean startBehavior() {
            try {
              animInstance().notifyBehavioralMethodEntered("startBehavior",
                  new ArgData[] {
                   });
              return super.startBehavior();
            }
            finally {
              animInstance().notifyMethodExit();
            }
        }
        public int takeEvent(RiJEvent event) { 
            try { 
              //animInstance().notifyTakeEvent(new AnimEvent(event));
              animInstance().notifyBehavioralMethodEntered("takeEvent",
                  new ArgData[] { new ArgData(RiJEvent.class, "event", event.toString())
                   });
              return super.takeEvent(event); 
            }
            finally { 
              animInstance().notifyMethodExit();
            }
        }
        /**  see com.ibm.rational.rhapsody.animation.AnimatedReactive interface */
        public AnimInstance animInstance() { 
            return ScheduleApplication.this.animInstance(); 
        }
        
    }
    //#[ ignore
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimClass getAnimClass() { 
        return animClassScheduleApplication; 
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public Object getFieldValue(java.lang.reflect.Field f, Object userInstance) { 
         Object obj = null;
         try {
             obj = f.get(userInstance);
         } catch(Exception e) {
              System.err.println("Exception: getting Field value: " + e);
              e.printStackTrace();
         }
         return obj;
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimInstance animInstance() {
        if (animate == null) 
            animate = new Animate(); 
        return animate; 
    } 
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addAttributes(AnimAttributes msg) {
        
        msg.add("requestedFloors", requestedFloors);
        msg.add("selectedFloors", selectedFloors);
        msg.add("isTaskQueueEmpty", isTaskQueueEmpty);
        msg.add("liftCalls", liftCalls);
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addRelations(AnimRelations msg) {
        
        msg.add("itsLift", false, true, itsLift);
    }
    /** An inner class added as instrumentation for animation */
    public class Animate extends AnimInstance { 
        public  Animate() { 
            super(ScheduleApplication.this); 
        } 
        public void addAttributes(AnimAttributes msg) {
            ScheduleApplication.this.addAttributes(msg);
        }
        public void addRelations(AnimRelations msg) {
            ScheduleApplication.this.addRelations(msg);
        }
        
        public void addStates(AnimStates msg) {
            if ((reactive != null) && (reactive.isTerminated() == false))
              reactive.rootState_add(msg);
        }
        
    } 
    //#]
    
}
/*********************************************************************
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/ScheduleApplication.java
*********************************************************************/

